import queryString from 'query-string'
import {
    reqUpdateUser
} from '../../api'
const {
    username,
    id,
    profile
} = queryString.parse(location.search)

const name = document.getElementById('username')
const preview = document.getElementById('preview')
const pic = document.getElementById('profile')
const _id = document.getElementById('_id')
_id.value = id
name.value = username
preview.src = `http://zsjyyds.online:90${profile}`
const updateForm = document.getElementById('updateForm')
pic.onchange = e => {
    const file = e.target.files[0]
    const fileReader = new FileReader()
    fileReader.readAsDataURL(file)
    fileReader.onload = () => {
        preview.src = fileReader.result
    }
}
updateForm.onsubmit = async (e) => {
    e.preventDefault()
    const formData = new FormData(updateForm)
    const result = await reqUpdateUser(formData)
    if (result.code == 200) {
        window.location = '/users.html'
    }
}